mui.init({

});

var keywordsData;
mui.plusReady(function () {
    open_soft_keyboard({
        input: ".searchWords_box"
    });
    keywordsData = new Vue({
        el: '#dataListBox',
        data: {
            userWords: '',
            category: '',
        },
        mounted() {
            this.getKeywords();
        },
        methods: {
            getKeywords: function () {
                //showWatting();
                var self = this;
                //获取搜索热词
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url: api_host + '/api/other/other/getSearchKeywords',
                    dataType: 'json',
                    type: 'get',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:1000,
                    success: function (msg) {
                        if(msg.code == 1){
                            self.category = msg.data;
                        }else{
                            mui.toast(msg.msg, {duration: '800',type: 'div'});
                        }
                    },
                    error:function () {
                        console.log('搜索热词加载失败');
                    },
                    complete:function () {
                        plus.nativeUI.closeWaiting();
                    }
                })
            },
            search_all: function () {
                var self = this;
                //输入关键词搜索
                if (this.userWords == '') {
                    mui.toast('请输入您要搜索的内容', {duration: '2000',type: 'div'});
                    return false;
                } else {
                    $('.searchWords_box').blur();
                    //打开搜索界面
                    mui.openWindow({
                        url: 'search.html',
                        createNew: false,
                        extras: {
                            'keywords': self.userWords
                        },
                        show: {
                            autoShow: true,
                            aniShow: 'slide-in-top',
                            duration: 100
                        },
                        waiting: {
                            autoShow: false,
                        }
                    });
                }
            },
            search_hot: function (keywords) {
                //点击搜索热词开始搜索
                $('.searchWords_box').blur();
                this.userWords = keywords;
                //打开搜索界面
                mui.openWindow({
                    url: 'search.html',
                    createNew: false,
                    extras: {
                        'keywords': keywords
                    },
                    show: {
                        autoShow: true,
                        aniShow: 'slide-in-top',
                        duration: 100
                    },
                    waiting: {
                        autoShow: false,
                    }
                });
            },
        }
    })
})
